package com.lefevre.cms.controller;

import com.lefevre.cms.bean.links.Links;
import com.lefevre.cms.common.ApiResult;
import com.lefevre.cms.service.links.LinksService;
import com.lefevre.cms.web.action.fileSystem.FileManage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class FriendLinksController {

    @Resource
    LinksService linksService;
    @Resource
    FileManage fileManage;

    @RequestMapping("/friend/links/list")
    public ApiResult<List<Links>> list(@RequestParam(defaultValue = "1", required = false) Integer current,
                                       @RequestParam(defaultValue = "10", required = false) Integer size) throws Exception {
        List<Links> linksList = linksService.findAllLinks_cache();
        if (linksList != null && linksList.size() > 0) {
            for (Links links : linksList) {
                links.setImage(fileManage.fileServerAddress() + links.getImage());
            }
        }
        return ApiResult.success(linksList);
    }
}
